package communication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

import message.Message;
import message.messageFactory.MessageFactory;

public abstract class Communicator extends Thread
{
	protected final MessageFactory messageFactory;
	private final ArrayList<MessageListener> listeners;
	
	public Communicator()
	{
		messageFactory = MessageFactory.getInstance();
		listeners = new ArrayList<MessageListener>();
	}
	protected void delegateMessageEvent(MessageReceivedEvent e)
	{
		for (MessageListener listener : listeners)
			if (listener.acceptsMessage(e.getMessage()))
				listener.messageRecieved(e);
	}
	public void addListener(MessageListener listener)
	{
		this.listeners.add(listener);
	}
	@Override
	public void run()
	{
		
	}
}
